#!/bin/sh
#
# Start olsrd ...
#
start() {
	echo -n "Starting olsrd ad hoc routing daemon... "

	if [ -f /var/run/olsrd.pid ]; then
		echo "FAILED!"
		echo "   -> olsrd already running or stale pid file"
	else
		/usr/sbin/olsrd -nofork >/dev/null 2>&1 &
		echo $! > /var/run/olsrd.pid
		echo "OK"
	fi
}	
stop() {
	echo -n "Stopping olsrd..."
	if [ -f /var/run/olsrd.pid ]; then
		kill `cat /var/run/olsrd.pid`
		rm /var/run/olsrd.pid
		echo "OK"
	else
		echo "FAILED!"
		echo "   -> Unable to locate pid file"
	fi
}
restart() {
	stop
	start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

